package com.javatom.notes.mongo.service;

import com.javatom.notes.mongo.po.XXObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.mapreduce.GroupBy;
import org.springframework.data.mongodb.core.mapreduce.GroupByResults;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MongoMapReduceService {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void  processMapReduce(){
        GroupByResults<XXObject> group = mongoTemplate.group("lm_process",
                GroupBy.key("audit_status").initialDocument("{ count: 0 }")
                        .reduceFunction("function(doc, prev) { prev.count += 1 }"), XXObject.class);
        log.error("group {}",group);
    }

}
